home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boostrs.arc / WORDIND.PAS < prev    next >
Pascal/Delphi Source File  |  1985-11-14  |  1KB  |  44 lines

  1. { ----------------------------
  2.   WORDIND returns the position
  3.   of WordNumber in S.
  4.   ---------------------------- }
  5. Function WordInd (          S : AnyString;
  6.                    WordNumber : Integer ) : Integer;
  7.  
  8. { Example: if S = 'I like Turbo Pascal' then
  9.               WordInd ( S, 3 ) = 8.  }
  10.  
  11. var
  12.    NumWords,  CurrentAddress, Len, Index
  13.              : integer;
  14.    NonBlank :  Boolean;
  15.  
  16. begin
  17.    Len := Length(S);
  18.    if Len = 0 then
  19.       WordInd := 0
  20.    else
  21.    begin
  22.       Index := 0;
  23.       NumWords := 0;
  24.       CurrentAddress := 0;
  25.       NonBlank := false;
  26.       repeat
  27.          CurrentAddress := CurrentAddress + 1;
  28.          if NonBlank then
  29.          begin
  30.             if S[CurrentAddress] = #32 then
  31.                NonBlank := false;
  32.          end
  33.          else
  34.          if S[CurrentAddress] <> #32 then
  35.          begin
  36.             NumWords := NumWords + 1;
  37.             if NumWords = WordNumber then
  38.                Index := CurrentAddress;
  39.             NonBlank := true;
  40.          end;
  41.       until (CurrentAddress = Len) or (Index > 0);
  42.       WordInd := Index;
  43.    end;
  44. end { WordInd };